%%% 
%%% a heng job module, used to calculate the word count
%%%
-module(wordcount2). 
-compile(export_all).

job_config() ->
    [{name, "word count"},	% 任务名称
    {vsn, "1.0"},			% 版本
 	{author, "cheng"}       % 作者    
 	].
 
input_data() ->
    [
		"http://hengproject.org/data1.txt",
 		"http://hengproject.org/data2.txt",
 		"http://hengproject.org/data3.txt",
        "http://hengproject.org/data4.txt"
 	].
 
%% Map函数
map(LineNo, Line) -> 
 	[{W, 1} || W <- word_in_line(Line)]. 	
    
%%  Reduce函数
reduce(Word, Iter) ->
    Result = 
    heng_iter:foldl
        (
        fun({Word, Values}, Acc) ->
            Acc + lists:sum(Values)
        end,
        0,
        Iter
        ),
    {Word, Result}.    
 
%% 将最终数据输出
output_result(Key, Data, Master) ->
    net_util:http_post("http://hengproject.org/output", Data).
